package cn.xorange.commons.system.controller.system;

import cn.xorange.commons.core.basic.bean.ResultBean;
import cn.xorange.commons.core.basic.controller.DataController;
import cn.xorange.commons.security.annotation.Authorize;
import cn.xorange.commons.system.entity.system.SysPost;
import cn.xorange.commons.system.service.System.ISysPostService;
import cn.xorange.commons.utils.lang.ObjectUtils;
import cn.xorange.commons.utils.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
import java.util.Set;

/**
 * @author : yangjian
 * date : 2025/1/9
 * description :
 */
@RestController
@Authorize(hasPerm = "system:post")
@RequestMapping("/system/post")
public class SysPostController extends DataController<SysPost, ISysPostService> {

    @GetMapping("roleId/{postIds}")
    public ResultBean getRoleIdsByPostId(@PathVariable Long[] postIds){
        String ids = service.getRoleIdsByPostId(postIds);
        if(StringUtils.isEmpty(ids)){
            return ResultBean.onSuccess();
        }else {
            String[] idArr = ids.split(",");
            Set<Long> roleIds = new HashSet<>();
            for (String id : idArr){
                roleIds.add(ObjectUtils.toLong(id));
            }
            return ResultBean.onSuccess(roleIds);
        }
    }
}
